package com.rygl.staff.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.rygl.common.annotation.Log;
import com.rygl.common.core.controller.BaseController;
import com.rygl.common.core.domain.AjaxResult;
import com.rygl.common.enums.BusinessType;
import com.rygl.staff.domain.Staff1;
import com.rygl.staff.service.IStaffService;
import com.rygl.common.utils.poi.ExcelUtil;
import com.rygl.common.core.page.TableDataInfo;

/**
 * 员工基础信息Controller
 * 
 * @author ruoyi
 * @date 2025-05-06
 */
@RestController
@RequestMapping("/staff/staff")
public class StaffController extends BaseController
{
    @Autowired
    private IStaffService staffService;

    /**
     * 查询员工基础信息列表
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:list')")
    @GetMapping("/list")
    public TableDataInfo list(Staff1 staff)
    {
        startPage();
        List<Staff1> list = staffService.selectStaffList(staff);
        return getDataTable(list);
    }

    /**
     * 导出员工基础信息列表
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:export')")
    @Log(title = "员工基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Staff1 staff)
    {
        List<Staff1> list = staffService.selectStaffList(staff);
        ExcelUtil<Staff1> util = new ExcelUtil<Staff1>(Staff1.class);
        util.exportExcel(response, list, "员工基础信息数据");
    }

    /**
     * 获取员工基础信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:query')")
    @GetMapping("/queryById/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {

        return success(staffService.selectStaffById(id));
    }

    /**
     * 获取员工岗位信息
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:query')")
    @GetMapping("/jobqueryById/{id}")
    public AjaxResult jobgetInfo(@PathVariable("id") Long id)
    {

        return success(staffService.selectjobById(id));
    }

    /**
     * 获取员工公积金社保薪资信息
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:query')")
    @GetMapping("/SalaryById/{id}")
    public AjaxResult SalarygetInfo(@PathVariable("id") Long id)
    {

        return success(staffService.selectSalaryById(id));
    }

    /**
     * 获取文件信息
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:query')")
    @GetMapping("/documentsById")
    public AjaxResult getDocumentsById(@RequestParam("id") Long id,
                                       @RequestParam("type") Integer type) {
        // 示例业务逻辑，实际根据 id 和 type 查询附件
        return success(staffService.selectDocumentsById(id, type));
    }

    /**
     * 查询操作log信息
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:query')")
    @GetMapping("/logById/{id}")
    public AjaxResult loggetInfo(@PathVariable("id") Long id)
    {


        return success(staffService.selectOperationLog(id));
    }

    /**
     * 查询调度log信息
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:query')")
    @GetMapping("/transferlogById/{id}")
    public AjaxResult transferloggetInfo(@PathVariable("id") Long id)
    {
        return success(staffService.selectStaffTransferLog(id));
    }
    /**
     * 查询合同
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:query')")
    @GetMapping("/contract/{id}")
    public AjaxResult contractgetInfo(@PathVariable("id") Long id)
    {
        return success(staffService.selectStaffContract(id));
    }

    /**
     * 新增员工基础信息
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:add')")
    @Log(title = "员工基础信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Staff1 staff)
    {
        return toAjax(staffService.insertStaff(staff));
    }

    /**
     * 修改员工基础信息
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:edit')")
    @Log(title = "员工基础信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Staff1 staff)
    {
        return toAjax(staffService.updateStaff(staff));
    }


    /**
     * 删除员工基础信息
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:remove')")
    @Log(title = "员工基础信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(staffService.deleteStaffByIds(ids));
    }
}
